package cn.yunwei.module.config;


import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.parameters.Parameter;
import org.springdoc.core.customizers.GlobalOpenApiCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/***
 * 创建Swagger配置
 * @author <a href="mailto:xiaoymin@foxmail.com">xiaoymin@foxmail.com</a>
 * 2025/3/22
 */
@Configuration
public class SwaggerConfig {

    @Bean
    public GlobalOpenApiCustomizer orderGlobalOpenApiCustomizer() {
        return openApi -> {
            // Add custom header for all requests
            if (openApi.getComponents() != null) {
                openApi.getComponents().addParameters("X-Custom-Header", new Parameter()
                        .in(ParameterIn.HEADER.toString())
                        .name("X-Custom-Header")
                        .description("Bearer yunWei")
                        .required(true)
                        .schema(new io.swagger.v3.oas.models.media.StringSchema()));
            }

            // You can also add other extensions or customize the OpenAPI response further
            openApi.addExtension("x-example-extension", "123");
        };
    }

    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("运维系统API")
                        .version("1.0")
                        .description("Knife4j集成springdoc-openapi示例")
                        .termsOfService("http://doc.xiaominfo.com")
                        .license(new License().name("Apache 2.0")
                                .url("http://doc.xiaominfo.com")));
    }
}